package com.ifood.web.controller.system;

import javax.servlet.http.HttpServletResponse;

import com.ifood.common.core.domain.entity.SysIconInfo;
import com.ifood.common.utils.poi.ExcelUtil;
import com.ifood.system.service.ISysIconInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ifood.common.annotation.Log;
import com.ifood.common.core.controller.BaseController;
import com.ifood.common.core.domain.AjaxResult;
import com.ifood.common.enums.BusinessType;
import com.ifood.common.core.page.TableDataInfo;

import java.util.List;

/**
 * icon管理Controller
 *
 * @author ifood
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/system/icon")
public class SysIconInfoController extends BaseController {
    @Autowired
    private ISysIconInfoService sysIconInfoService;

    /**
     * 查询icon管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:icon:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysIconInfo sysIconInfo) {
        startPage();
        List<SysIconInfo> list = sysIconInfoService.selectSysIconInfoList(sysIconInfo);
        return getDataTable(list);
    }

    /**
     * 导出icon管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:icon:export')")
    @Log(title = "icon管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysIconInfo sysIconInfo) {
        List<SysIconInfo> list = sysIconInfoService.selectSysIconInfoList(sysIconInfo);
        ExcelUtil<SysIconInfo> util = new ExcelUtil<SysIconInfo>(SysIconInfo.class);
        util.exportExcel(response, list, "icon管理数据");
    }

    /**
     * 获取icon管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:icon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysIconInfoService.selectSysIconInfoById(id));
    }

    /**
     * 新增icon管理
     */
    @PreAuthorize("@ss.hasPermi('system:icon:add')")
    @Log(title = "icon管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysIconInfo sysIconInfo) {
        return toAjax(sysIconInfoService.insertSysIconInfo(sysIconInfo));
    }

    /**
     * 修改icon管理
     */
    @PreAuthorize("@ss.hasPermi('system:icon:edit')")
    @Log(title = "icon管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysIconInfo sysIconInfo) {
        return toAjax(sysIconInfoService.updateSysIconInfo(sysIconInfo));
    }

    /**
     * 删除icon管理
     */
    @PreAuthorize("@ss.hasPermi('system:icon:remove')")
    @Log(title = "icon管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysIconInfoService.deleteSysIconInfoByIds(ids));
    }
}
